﻿package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.*;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ReflectedPacket_1 extends Sprite {
		
		private var ball_1:Ball;
		private var ball_2:Ball;
		
		private var Start_TextField: TextField ;
		private var Reset_TextField: TextField ;
		private var Amplitude_TextField: TextField ;
		
		public var center: Number;
		public var spread: Number;
		public var color: uint;
		private var wave_x: Number;
		private var delta_x: Number;
		private var wave_y;
		private var wave_1_y;
		private var wave_2_y;
		private var reflector: Number;
		private var speed: Number = 4;
		private var i: uint = 0;
		private var alph: Number;
		private var ampl_2: Number;
		
		private var go: Boolean = false;
		
		
		public function ReflectedPacket_1(center:Number = 100, spread:Number = 20, color:uint=0xff0000)
		{
			this.center = center;
			this.spread = spread;
			this.color = color;
			this.alph = alph;
			this.ampl_2 = ampl_2;
			
			
			init();
		}
		public function init():void {
			
			spread = 30;
			center = 100;
			wave_x = 10;
			delta_x = 2;
			reflector = 250;
			alph = 1;
			ampl_2 = 50;
			
			/*ball_1 = new Ball(5, 0x00ff00);
			addChild(ball_1);
			ball_1.x = 15;
			ball_1.y = 150;
			ball_1.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_1);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			
			ball_2 = new Ball(5, 0xff0000);
			addChild(ball_2);
			ball_2.x = 15;
			ball_2.y = 170;
			ball_2.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown_2);*/
			
								
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
				
		}
	
		/*public function onMouseDown_1(event:MouseEvent):void 
		{
			//This is the Fire/Pause button
			
			if(go){go = false;}
			else{go = true;
			
		}
		public function onMouseDown_2(event:MouseEvent):void {
			//This is the reset button
									
			go = false;
			
		}*/
	
						
			}

	
		
		public function onEnterFrame(event:Event):void {
			
			if(center < 700){
			graphics.clear();
			center += speed;
			
			
			graphics.lineStyle(3, 0x000000, 1 - alph);
			graphics.moveTo(reflector, 100);
			graphics.lineTo(reflector, 300);
			
			graphics.lineStyle(1, 0x000000, 1);
			graphics.moveTo(reflector, 200);
			graphics.lineTo(0, 200);
						
						
			for(i = 0; i < (2*reflector/delta_x); i++)
			{
			wave_x =  i*delta_x;
			wave_y = 200 + wave_1_y + wave_2_y;
			
			wave_1_y = -(50*Math.exp(-((wave_x - center)*(wave_x - center)/(spread*spread))));
			wave_2_y = -(ampl_2*Math.exp(-((wave_x - (2*reflector - center))*(wave_x - (2*reflector - center))/(spread*spread))));
									
			if(i < (reflector/delta_x))
			{
			graphics.lineStyle(2, 0x00ff00, 1);
			}
			else
			{
			graphics.lineStyle(2, 0x00ff00, alph);
			}
			graphics.lineTo(wave_x, 200 + wave_1_y);
			}
			graphics.moveTo(0,200);
			
			for(i = 0; i < (2*reflector/delta_x); i++)
			{
			wave_x =  i*delta_x;
			wave_y =  wave_1_y + wave_2_y;
			
			wave_1_y = -(50*Math.exp(-((wave_x - center)*(wave_x - center)/(spread*spread))));
			wave_2_y = -(ampl_2*Math.exp(-((wave_x - (2*reflector - center))*(wave_x - (2*reflector - center))/(spread*spread))));
			
			if(i < (reflector/delta_x))
			{
			graphics.lineStyle(2, 0xff0000, 1);
			}
			else
			{
			graphics.lineStyle(2, 0xff0000, alph);
			}
			
			graphics.lineTo(wave_x, 200 + wave_2_y);
			}
			graphics.moveTo(0,200);
			
			for(i = 0; i < (2*reflector/delta_x); i++)
			{
			wave_x =  i*delta_x;
			wave_y =  wave_1_y + wave_2_y;
			
			wave_1_y = -(50*Math.exp(-((wave_x - center)*(wave_x - center)/(spread*spread))));
			wave_2_y = -(ampl_2*Math.exp(-((wave_x - (2*reflector - center))*(wave_x - (2*reflector - center))/(spread*spread))));
			
			
			if(i < (reflector/delta_x))
			{
			graphics.lineStyle(2, 0x000000, 1);
			}
			else
			{
			graphics.lineStyle(2, 0x000000, alph);
			}
			
			graphics.lineTo(wave_x, 200 + wave_y);
			}
			graphics.moveTo(0,200);
			
			
			/*graphics.lineTo(wave_x, 200 + 50*Math.exp(-((wave_x - center)*(wave_x - center)/(spread*spread))) 
						- 50*Math.exp(-((wave_x - (2*reflector - center))*(wave_x - (2*reflector - center))/(spread*spread))));*/
			}
			/*graphics.lineStyle(1, 0x888888, 1);
			graphics.beginFill(0x000000);
			graphics.drawRoundRect(wave_x - 3, 200 + 50*Math.exp(-((wave_x - center)*(wave_x - center)/(spread*spread)))
							+ 50*Math.exp(-((wave_x - (2*reflector - center))*(wave_x - (2*reflector - center))/(spread*spread)))-2, 6,4, 5, 2); 
			graphics.endFill();*/
			
	}
	
			
}
			
				
		
		
		
		

